package com.leokok.jts.learning.jts.core.algorithm.match;

import org.junit.Test;
import org.locationtech.jts.algorithm.match.AreaSimilarityMeasure;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

/**
 * 相似性匹配
 */
public class SimilarityMeasureTest {

    /**
     * 通过面积判断相似性
     * 相交面积比值 [0, 1] 越接近 1相似性越高
     */
    @Test
    public void areaSimilarityMeasure() throws ParseException {
        WKTReader wktReader = new WKTReader();
        Geometry g1= wktReader.read("POLYGON ((115.958 31.998, 115.951 31.982, 115.96 31.968, 115.9925 31.9645, 116.011 31.986, 116.0065 32.0105, 115.958 31.998))");
        Geometry g2 = wktReader.read("POLYGON ((115.935 32.001, 115.917 31.972, 115.944 31.95, 115.976 31.962, 115.992 31.992, 115.958 32.012, 115.935 32.001))");

        AreaSimilarityMeasure areaSimilarityMeasure = new AreaSimilarityMeasure();
        System.out.println(areaSimilarityMeasure.measure(g1,g2));
    }
}
